const joi = require('joi');
const validationMiddleware = require('../../middleware/validate');
const { dealNotEmpty } = require('../../utils/dberrordeal');
const CategoryController = require('../../controllers/good/categoryController');
const router = require('koa-router')();
router.prefix('/category');
const rulesSchema = {
    '/category/addcategory': joi.object({
        name: dealNotEmpty('分类名称'),
    }),
    '/category/putcategory': joi.object({
        name: dealNotEmpty('分类名称'),
        id: dealNotEmpty('分类id'),
    }),
    '/category/getcategory': joi.object({
        id: dealNotEmpty('分类id'),
    }),
    '/category/delcategory': joi.object({
        id: dealNotEmpty('分类id'),
    }),
}

router.post('/addcategory', validationMiddleware(rulesSchema), CategoryController.createCategory);
router.post('/putcategory', validationMiddleware(rulesSchema), CategoryController.updateCategory);
router.post('/getcategory', validationMiddleware(rulesSchema), CategoryController.getCategoryById);
router.post('/delcategory', validationMiddleware(rulesSchema), CategoryController.deleteCategory);
router.post('/getcategorylist', CategoryController.getCategoryList);
module.exports = router;